home *** CD-ROM | disk | FTP | other *** search
/ Biodiversity of Illinois 2: Woodland Habitats / Biodiversity of Illinois 2 - Woodland Habitats.iso / mac / casts / PDFxtraBehaviors.cst / 00016_Script_PDF_FindText < prev    next >
Text File  |  2006-07-11  |  7KB  |  179 lines

  1. -- Find Text
  2.  
  3. Property pEvent, pSprite, pFindMember, pCaseSensitive, pWholeWord, pWrap, pAlertFlag
  4.  
  5. on doFindText me
  6.   
  7.   -- get the text to search for from the text member
  8.   myMember = me.ExtractMemberFromString(pFindMember)[2]
  9.   f = myMember.text
  10.   set err = PDF_findText(sprite pSprite, f, pCaseSensitive, pWholeWord, pWrap)
  11.   if PDF_status(sprite pSprite) then alert "PDF Behavior Error"&RETURN&PDF_error(sprite pSprite)
  12. end doFindText
  13.  
  14. on mouseUp me
  15.   if (pEvent = #mouseUp) then doFindText(me)
  16. end mouseUp
  17.  
  18. on mouseDown me
  19.   if (pEvent = #mouseDown) then doFindText(me)
  20. end mouseDown
  21.  
  22. -- standard behavior stuff --
  23. on getPropertyDescriptionList me
  24.   set defaultValues = GetDefaultValues (me)
  25.   
  26.   set pdfSpriteList = getProp (defaultValues, #spriteList)
  27.   set defSprite     = getProp (defaultValues, #defaultSprite)
  28.   
  29.   -- retrieve all members of type text, field or Flashcomponent
  30.   lTextFields = me.GetMembers([#text, #field, #flashcomponent])
  31.   if (lTextFields = []) then
  32.     if the currentSpriteNum then
  33.       alert "You need at least one member of type #field or #text to use this behavior."
  34.     end if
  35.     exit
  36.   end if 
  37.   
  38.   set p_list = [:]
  39.   addprop p_list, #pEvent, [ #comment: "Event", #format:#symbol, #range:[#mouseUp, #mouseDown], #default:#mouseUp]
  40.   addprop p_list, #pSprite, [ #comment: "PDF Sprite is in channel:", #format:#symbol, #range:pdfSpriteList, #default:defSprite]
  41.     if (lTextFields.count = 0) then
  42.     addprop p_list, #pFindMember, [ #comment: "String to find is in:", #format: #string, #default:"<no named fields or text members available>"]
  43.   else  
  44.     addprop p_list, #pFindMember, [ #comment: "String to find is in:", #format:#member, #default:lTextFields[1], #range:lTextFields]
  45.   end if  
  46.   
  47.   addprop p_list, #pCaseSensitive, [ #comment: "Match case:", #format:#boolean, #default:FALSE]
  48.   addprop p_list, #pWholeWord, [ #comment: "Match whole words only:", #format:#boolean, #default:FALSE]
  49.   addprop p_list, #pWrap, [ #comment: "Reset (find first occurrence):", #format:#boolean, #default:TRUE] 
  50.   return p_list
  51. end
  52.  
  53. on getBehaviorDescription
  54.   tmp = "Find a string in the PDF document. The string is specified in a Director field." & RETURN& "Available for Windows only with full version of Acrobat."
  55.   tmp = tmp &RETURN&RETURN& "--- PARAMETERS ---"
  56.   tmp = tmp &RETURN& " - Event: mouseUp or mouseDown" &RETURN& " - PDF Sprite is in channel: which channel contains the PDF Sprite"
  57.   tmp = tmp&RETURN& "- String to find is in: the field cast member that contains the text to search for in the PDF document."
  58.   tmp = tmp &RETURN& " - Match case: If checked, the search is case-sensitive."
  59.   tmp = tmp &RETURN& " - Match whole words only: If checked, only whole word matches are found."
  60.   tmp = tmp &RETURN& " - Reset (find first occurrence): Check this box if you wish to find the first occurrence. Keep unchecked if you wish to find the next occurrence relative to the current position in the document."  
  61.   tmp = tmp &RETURN&RETURN& "Free to use and abuse. (c)1999-2005, Integration New Media, Inc."  &RETURN& "Thanks to James Newton for his suggestions."
  62.   return tmp  
  63. end
  64.  
  65.  
  66. on getBehaviorTooltip
  67.   return "Find a string in the PDF document."& RETURN& "The string is specified in a Director field." & RETURN& "Available for Windows only with full version of Acrobat."
  68.   
  69.   -- utils --
  70. on GetDefaultValues me
  71.   if the currentSpriteNum then
  72.     set spriteList = GetSpriteList (me #PDF)
  73.     if count (spriteList) then
  74.       set defaultSprite = getAt (spriteList, 1)
  75.     else
  76.       set defaultSprite = 0
  77.     end if
  78.     
  79.     return [#spriteList: spriteList, #defaultSprite: defaultSprite]
  80.     
  81.   else -- the currentSpriteNum = 0
  82.     -- Director is merely recompiling this script: return dummy values
  83.     return [#spriteList: [1], #defaultSprite: 1]
  84.   end if
  85. end 
  86.  
  87.  
  88. on GetSpriteList me, memberType
  89.   -- return list of sprites of type memberType in current frame
  90.   global version
  91.   if (char 1 of version = 6) then
  92.     set maxSprite = 120
  93.   else
  94.     set maxSprite = the lastChannel
  95.   end if
  96.   
  97.   set aList=[]
  98.   
  99.   repeat with i = 1 to maxSprite
  100.     set spriteMember = the member of sprite i
  101.     -- if (string(m) contains "member 0") then next repeat -- unnecessary
  102.     if (the type of spriteMember = memberType) then -- (JN) Line break
  103.       append (aList, i)
  104.     end if
  105.   end repeat
  106.   
  107.   return aList
  108. end GetSpriteList
  109.  
  110.  
  111. on GetMembers me, theMembersTypeNeeded  
  112.   
  113.   lResult = []
  114.   
  115.   lCastLib = the number of castLibs
  116.   
  117.   repeat while lCastLib -- repeat through all linked castlibs
  118.     
  119.     lMemberNum = the number of members of castLib(lCastLib)
  120.     
  121.     repeat while lMemberNum -- repeat through all members of the current castlib
  122.       lMemberType = member(lMemberNum, lCastLib).type
  123.       
  124.       if (theMembersTypeNeeded.getOne(lMemberType) > 0) then -- check if the member's type is contained in theMembersTypeNeeded
  125.         lName = member(lMemberNum, lCastLib).name 
  126.         if (lName <> "") then 
  127.           
  128.           lResult.AddAt(1, lName&&"(member"&&lMemberNum&&"of castlib"&&lCastLib&")") -- Add the member to the list
  129.         end if
  130.       end if
  131.       
  132.       set lMemberNum = lMemberNum - 1 -- check the next member
  133.     end repeat
  134.     
  135.     set lCastLib = lCastLib - 1 -- check the next castlib
  136.   end repeat
  137.   
  138.   return lResult
  139. end GetMembers
  140.  
  141. --
  142. -- Extract name and reference to a member contained in a string
  143. --    in a list [<name>, <(member xxx of castlib yyy)>]
  144. -- the String contains a reference to a member formatted like
  145. --    "<member name> (member xxx of castlib yyy)"
  146. --
  147. on ExtractMemberFromString me, theString
  148.   lResult = ["", VOID]
  149.   
  150.   if (StringP(theString)) then -- check if theString contains a string
  151.     lPos = offset("(member ", theString) -- find the offset of the substring "(member "
  152.     if (lPos > 0) then -- substring found = theString is a valid member reference
  153.       lName= ""
  154.       
  155.       if (lPos > 2) then
  156.         lName = theString.char[1..lPos-2]
  157.         if (lName) = "<no name>" then
  158.           lName = ""
  159.         end if
  160.       end if
  161.       
  162.       lMember = value(theString.char[lPos..theString.chars.count])
  163.       -- check if the member name and member reference are consistent
  164.       if (lMember <> VOID) then
  165.         if (lMember.name <> lName) then -- the user probably moved the cast member, we'll try to find it
  166.           if (lName <> "") then -- the member didn't have a name, so it's useless to look for it
  167.             lMember = member(lName)
  168.           else
  169.             lMember = VOID
  170.           end if
  171.         end if
  172.       end if
  173.       
  174.       lResult = [lName, lMember]
  175.     end if
  176.   end if
  177.   
  178.   return lResult
  179. end ExtractMemberFromString